package com.JohnCarloSalter.Receipt;

import java.util.Calendar;

public class Receipt implements ReceiptComponent {
	private StoreHeader header;
	private Purchases purchases;
	private SalesTax tax;
	private Calendar date;
	private double subtotal;
	private double amountDue;
	
	//Minimal Constructor
	public Receipt(Purchases p, Calendar d) {
		header = null;
		purchases = p;
		tax = null;
		date = d;
		subtotal = p.getTotal();
		amountDue = subtotal; //This assumes no sales tax.
	}
	
	public void print() {
		System.out.println(header.toString());
		System.out.println();
		System.out.println("Date: " + (date.get(Calendar.MONTH) + 1) + "/" +  date.get(Calendar.DAY_OF_MONTH) + "/" + date.get(Calendar.YEAR));
		System.out.println();
		System.out.printf("%-30s%35s\n", "Items(x quantity)", "Price per unit");
		System.out.println(purchases.toString());
		System.out.println("");
		System.out.println("Subtotal: " + subtotal);
		System.out.println("Tax: " + String.format("%.2f", getSalesTax()));
		System.out.println("Total: $" + String.format("%.2f", amountDue));
		System.out.println();		
	}
	
	//Adders=============================
	public void addStoreHeader(StoreHeader h) {
		header = h;
	}
	
	//Sort of a setter.
	public void addTaxMethod(SalesTax t) {
		tax = t;
		amountDue = amountDue + tax.getSalesTax(date, subtotal);
	}
	//End Adders=========================
	
	//Utility Methods====================	
	private double getSalesTax() {
		if(tax == null) {
			return 0;
		} else {
			return tax.getSalesTax(date, subtotal);
		}
	}
	
	//Getters============================
	public Purchases getPurchases() { return purchases;	}
	public double getSubtotal() { return subtotal; }
	
}
